#include "NaTools.hpp"
#include <fstream>
using namespace std;

const int N = 10000;
const double _left = -5;
const double _right = 5;
double step = (_right-_left)/N;

vector<double> x;

class T:public func{
public:
	double operator ()(double x){
		return 1/(1+x*x);
	}
};

T f;
ofstream outfile;

void init(){
	double loc = _left;
	for(int i=0;i<=N;i++){
		x.push_back(loc);
		loc+=step;
	}
	outfile << "[" ;
	for(int i=0;i<=N;i++){
		if(i==N) outfile << f(x[i]);
		else outfile << f(x[i]) << ",";
	}
	outfile << "]" << endl;
}

void plot(int n){
	outfile << "[" ;
	vector<double> zeros;
	double loc = _left;
	for(int i=0;i<=n;i++){
		zeros.push_back(loc);
		loc += (_right-_left)/n;
	}
	Newton_inter newinter(f,zeros);
	// newinter.latex();
	for(int i=0;i<=N;i++){
		if(i==N) outfile << newinter(x[i]);
		else outfile << newinter(x[i]) << ",";
	}
	outfile << "]" << endl;
}

int main(){
	outfile.open("plot_B.dat");
	outfile << N << " " << _left << " " << _right << endl;
	init();
	for(int i=2;i<=8;i+=2) plot(i);
	outfile.close();
}